<template>
    <div>
        <div>
          <loadingComponent
          :show="loading.show"
          :text="loading.text"
          />
            <alertComponent  
                :show="alert.show"
                :title="alert.title"
                :message="alert.message"
                :buttons="alert.buttons"/>

            <!--<button @click="alertShowMethod">打开弹窗</button>
            <button @click="loadingShowMethod">显示loading</button>-->
        </div>
        <router-view/>
    </div>
</template>
<script type="es6">
    import './../css/common.css' ;
    import loadingComponent from './../components/loading' ;
    import alertComponent from './../components/alert' ;
    export default {
        data(){
            return {
                message:'ssss',
                pullMessage:undefined,
                alertShow:undefined,
                alert:{
                    show:false,
                    message:undefined,
                    title:undefined,
                    buttons:[]
                },
                loading:{
                    show:false ,
                    text:undefined
                }
            }
        },
        components:{
           loadingComponent,
           alertComponent
        },
        beforeMount(){
            //alert消息提示
            window.alert =(message,callback) => {
                if(typeof message === "function") {
                    callback = message;
                };
                callback = callback || function () {};
                this.alert = {
                    ...this.alert,
                    show:true,
                    message:message,
                    title:'消息提示',
                    buttons:[
                        {
                            text:"确定",
                            press:()=> {
                                if(callback() === false) return;
                                this.alert.show = false;
                            },
                            className:"ok"
                        }
                    ]
                }
            }
            //loading显示
            window.loading = ( text ) => {
                this.loading = {
                    ...loading,
                    show:true,
                    text:text
                }
            }
            //loading关闭
            window.loadingClose = ( text) => {
                this.loading = {
                    ...loading,
                    show:false,
                    text:text
                }
            }
        },
        mounted(){
           
        },
        methods:{
            getData :() =>{
                // alert('11')
            },
            up(aa){
                this.pullMessage = aa() ;
            },
            alertShowMethod(){
                alert('1',function(params) {
                    console.log('1')
                })
            },
            loadingShowMethod(){
                loading('持续加载中...') ;
                setTimeout(function() {
                    loadingClose();
                }, 3000);
            }
        }
    }
</script>